from flask import Flask
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from blueprints import animals, notices, files
from extension import db  # 防止循环引用


def create_app():
    app = Flask(__name__, static_folder='static')

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://root:root@localhost:3306/db_animal?charset=utf8mb4"
    app.config['CHARSET'] = 'utf-8'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # True跟踪数据库的修改，及时发送信号

    CORS(app, resources={r'/*': {'origins': '*'}})

    db.init_app(app)

    app.register_blueprint(animals.bp)
    app.register_blueprint(notices.bp)
    app.register_blueprint(files.bp)

    return app


app = create_app()

if __name__ == '__main__':
    app.run(debug=True)
